﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyClassUI.entity;
using EasyClassUI.WebRequest;

namespace EasyClassUI.forms.group
{
    public partial class CreateNewGroup : Form
    {
        public CreateNewGroup()
        {
            InitializeComponent();
            errorMessageLabel.Visible = false;
        }

        private void ConfirmButton_Click(object sender, EventArgs e) {
            StudyGroup newGroup = new StudyGroup() { StudyGroupName = GroupNameText.Text, Description = DescriptionText.Text , Category = CategoryText.Text};
            GroupService groupService = new GroupService();
            CreateGroupStatus errorMsg = groupService.CreateGroup(User.CurrentUser.Token, newGroup);
            if (errorMsg.Status == "200") {
                errorMessageLabel.Visible = true;
                User.Message.Add($"You created group {newGroup.StudyGroupName}");
                errorMessageLabel.Text = "Successed!";
            }

            else if (errorMsg.Status == "400") {
                errorMessageLabel.Visible = true;
                errorMessageLabel.Text = "Group has exsisted!";
            }

            else {
                errorMessageLabel.Visible = true;
                errorMessageLabel.Text = "Please check your network, something went wrong.";
            }
        }

        private void CloseButton_Click(object sender, EventArgs e) {
            groupUC.groupView.showAllMyAddedGs();
            this.Close();
        }
    }
}
